﻿using ZeroSum.Constants;
using ZeroSum.DependencyInjection.Attributes;
using ZeroSum.Domain.Repositories;
using ZeroSum.Plugin.Authorization.Datas.Aggregates.MenuAggregate;
using ZeroSumZSA.Core.Aggregates.MenuAggregate;

namespace ZeroSumZSA.Core.DomainServices.Menus;

[Register]
public class MenuDataSeedProvider : IDataSeedProvider
{
    private readonly IRepository<Menu> _repository;

    public MenuDataSeedProvider(IRepository<Menu> repository)
    {
        _repository = repository;
    }

    public async Task GenerateAsync()
    {
        if (await _repository.CountAsync() <= 0)
        {
            var auth = new Menu
            {
                Id = 142307070910563,
                Name = "权限管理",
                Code = "auth_manager",
                Type = MenuType.Dir,
                Icon = "safety-certificate",
                Router = "/auth",
                Component = "PageView",
                Application = "manage",
                OpenType = MenuOpenType.None,
                Weight = MenuWeight.SuperAdminWeight,
                Sort = 100
            };

            var menus = new List<Menu>
            {
                new()
                {
                    Id = 142307070910564,
                    Parent = auth,
                    Name = "用户管理",
                    Code = "sys_user_mgr",
                    Type = MenuType.Menu,
                    Router = "/mgr_user",
                    Component = "system/user/index",
                    Application = "manage",
                    OpenType = MenuOpenType.Component,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914651,
                    Parent = auth,
                    Name = "角色管理",
                    Code = "sys_role_mgr",
                    Type = MenuType.Menu,
                    Router = "/role",
                    Component = "system/role/index",
                    Application = "manage",
                    OpenType = MenuOpenType.Component,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },

                new()
                {
                    Id = 142307070910565,
                    Name = "用户查询",
                    Code = "sys_user_mgr_page",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:page",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910566,
                    Name = "用户编辑",
                    Code = "sys_user_mgr_edit",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:edit",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910567,
                    Name = "用户增加",
                    Code = "sys_user_mgr_add",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:add",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910568,
                    Name = "用户删除",
                    Code = "sys_user_mgr_delete",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:delete",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910569,
                    Name = "用户详情",
                    Code = "sys_user_mgr_detail",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:detail",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910570,
                    Name = "用户导出",
                    Code = "sys_user_mgr_export",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:export",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910572,
                    Name = "用户授权角色",
                    Code = "sys_user_mgr_grant_role",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:GrantUserRole",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910573,
                    Name = "用户拥有角色",
                    Code = "sys_user_mgr_own_role",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:ownRole",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910577,
                    Name = "用户修改密码",
                    Code = "sys_user_mgr_update_pwd",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:UpdatePwd",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910579,
                    Name = "用户修改头像",
                    Code = "sys_user_mgr_update_avatar",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:UpdateAvatar",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070910580,
                    Name = "用户重置密码",
                    Code = "sys_user_mgr_reset_pwd",
                    Type = MenuType.Btn,
                    Permission = "api:admin:User:resetPwd",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070918777,
                    Name = "用户登录信息",
                    Code = "sys_user_mgr_login",
                    Type = MenuType.Btn,
                    Permission = "api:admin:getLoginUser",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },

                new()
                {
                    Id = 142307070914652,
                    Name = "角色查询",
                    Code = "sys_role_mgr_page",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Role:page",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914653,
                    Name = "角色增加",
                    Code = "sys_role_mgr_add",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Role:add",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914654,
                    Name = "角色编辑",
                    Code = "sys_role_mgr_edit",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Role:edit",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914655,
                    Name = "角色删除",
                    Code = "sys_role_mgr_delete",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Role:delete",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914656,
                    Name = "角色详情",
                    Code = "sys_role_mgr_detail",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Role:detail",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914657,
                    Name = "角色下拉",
                    Code = "sys_role_mgr_drop_down",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Role:List",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914658,
                    Name = "角色授权菜单",
                    Code = "sys_role_mgr_grant_menu",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Role:GrantMenu",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914659,
                    Name = "角色拥有菜单",
                    Code = "sys_role_mgr_own_menu",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Role:OwnMenu",
                    Application = "manage",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914633,
                    Name = "平台管理",
                    Code = "sys_platform",
                    Type = MenuType.Dir,
                    Icon = "safety-certificate",
                    Router = "/platform",
                    Component = "PageView",
                    Application = "system",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914642,
                    Name = "菜单管理",
                    Code = "sys_menu_mgr",
                    Type = MenuType.Menu,
                    Router = "/menu",
                    Component = "system/menu/index",
                    Application = "system",
                    OpenType = MenuOpenType.Component,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914643,
                    Name = "菜单列表",
                    Code = "sys_menu_list",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Menu:list",
                    Application = "system",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914644,
                    Name = "菜单增加",
                    Code = "sys_menu_add",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Menu:add",
                    Application = "system",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914645,
                    Name = "菜单编辑",
                    Code = "sys_menu_edit",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Menu:edit",
                    Application = "system",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914646,
                    Name = "菜单删除",
                    Code = "sys_menu_delete",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Menu:delete",
                    Application = "system",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                },
                new()
                {
                    Id = 142307070914647,
                    Name = "菜单详情",
                    Code = "sys_menu_detail",
                    Type = MenuType.Btn,
                    Permission = "api:admin:Menu:detail",
                    Application = "system",
                    OpenType = MenuOpenType.None,
                    Weight = MenuWeight.SuperAdminWeight,
                    Sort = 100
                }
            };

            await _repository.AddRangeAsync(menus);
            await _repository.SaveChangesAsync();
        }
    }

    public int Order { get; set; } = 1;
}